import { GameMapItemType } from './../../game/GameDefine';

import GameMapItemWidget from './GameMapItemWidget';

const {ccclass, property, menu} = cc._decorator;

@ccclass
@menu("Widget/Game/GameMapItemDoorWidget")
export default class GameMapItemDoorWidget extends GameMapItemWidget {
    @property(cc.Sprite)
    img_door: cc.Sprite = null;

    @property(cc.SpriteFrame)
    sf_door: cc.SpriteFrame = null;

    @property(cc.SpriteFrame)
    sf_doorOpen: cc.SpriteFrame = null;

    public override initWithItem(itemType: GameMapItemType): void {
        super.initWithItem(itemType);
        
        if(itemType == GameMapItemType.DOOR_V){
            this.node.angle = 90;
        }
        this.switchState(itemType);
    }

    public switchState(itemType: GameMapItemType){
        if(itemType == GameMapItemType.DOOR_H || itemType == GameMapItemType.DOOR_V){
            this.img_door.spriteFrame = this.sf_door;
        }else if(itemType == GameMapItemType.DOOR_OPEN){
            this.img_door.spriteFrame = this.sf_doorOpen;
        }
    }
}